package com.holic.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public final class JdbcUtil {
	
	//连接数据库的参数
	public static String url = null;
	public static String user = null;
	public static String driver = null;
	private static String password = null;
	
	private JdbcUtil () {}
	
	//初始化
	public static boolean init(){
		try{
			url = Configuration.getString("db.url");
			user = Configuration.getString("db.user");
			password = Configuration.getString("db.password");
			driver = Configuration.getString("db.driver");
			Class.forName(driver); //加载驱动
			return true;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			LOG.error("数据库驱动类加载失败");
			return false;
		}
	}
	
	//获得连接
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, user, password);
	}
	
	
}